package com.client.rpcclient;


import com.common.code.MyNettyDecoder;
import com.common.code.MyNettyEncoder;
import com.common.serialize.CommonSerializer;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.extern.slf4j.Slf4j;

/**
 * @author Zixiang Hu
 * @description
 * @create 2021-03-01-15:14
 */
@Builder
@Slf4j
@AllArgsConstructor
public class NettyClientInitializer extends ChannelInitializer<SocketChannel> {
    private CommonSerializer serializer;

    @Override
    protected void initChannel(SocketChannel ch) throws Exception {
        ChannelPipeline pipeline = ch.pipeline();
        pipeline.addLast(new MyNettyEncoder(serializer));
        pipeline.addLast(new MyNettyDecoder());
        pipeline.addLast(new NettyClientHandler());

    }
}
